package leetcode100;

import java.util.Arrays;

public class lc037 {
    public static void main(String[] args) {
        int[][] matrix = new int[][] {{1,2,3},{4,5,6},{7,8,9}};
        new lc037().rotate(matrix);

    }



    public void rotate(int[][] matrix) {
        int n = matrix.length;
//        System.out.println(Arrays.deepToString(matrix));
        //转置
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;
            }
        }
//        System.out.println(Arrays.deepToString(matrix));
        //水平翻转
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n/2; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[i][n-1-j];
                matrix[i][n-1-j] = temp;
            }
        }
//        System.out.println(Arrays.deepToString(matrix));

    }
}
